﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiskFileUpload
{
    public class UploadPercnetHandler : System.Web.IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(System.Web.HttpContext context)
        {
            string key = context.Request[ DiskFileUpload.UploadFiles.DiskFileUpload_GUID];
            DiskFileUpload.UploadFiles item
                = context.Application[key] as DiskFileUpload.UploadFiles;

            int uploadPercent = 0;
            if (item != null)
            {
                uploadPercent = item.CompletePercent;
            }

            string json = string.Format(
                    "{{ \"percent\":{0} }}", uploadPercent
                );
            context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache);
            context.Response.ContentType = "application/json";
            context.Response.Write(json);

        }

        #endregion
    }
}
